#include "ControlMusic.h"
#include "HelloWorldScene.h"

ControlMusic::ControlMusic(void)
{
	initControlMusic();
}


ControlMusic::~ControlMusic(void)
{
}

void ControlMusic::initControlMusic()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCSprite *MusicBackGround = CCSprite::spriteWithFile(BACKGROUND[10].c_str());
	MusicBackGround->setPosition(ccp(size.width/2,size.height/2));
	addChild(MusicBackGround);

	size = CCDirector::sharedDirector()->getWinSize();
	CCMenu* pMenu = CCMenu::menuWithItems( NULL);
	pMenu->setPosition(CCPointZero);
	addChild(pMenu);

	CCLabelBMFont* pLabel1=CCLabelBMFont::labelWithString("Turn On",FONT);
	pLabel1->setScale(0.7f);
	CCMenuItemLabel* pMenuItem1 = CCMenuItemLabel::itemWithLabel(pLabel1, this, menu_selector(ControlMusic::TurnOn));
	pMenuItem1->setPosition(CCPointMake( size.width / 2,size.height/2+100));
	pMenu->addChild(pMenuItem1,1);

	CCLabelBMFont* pLabel2=CCLabelBMFont::labelWithString("Turn Off",FONT);
	pLabel2->setScale(0.7f);
	CCMenuItemLabel* pMenuItem2 = CCMenuItemLabel::itemWithLabel(pLabel2, this, menu_selector(ControlMusic::TurnOff));
	pMenuItem2->setPosition(CCPointMake( size.width / 2,size.height/2+40));
	pMenu->addChild(pMenuItem2,1);

	CCLabelBMFont* pLabel3=CCLabelBMFont::labelWithString("Back",FONT);
	pLabel3->setScale(0.7f);
	pLabel3->setColor(ccc3(0,250,120));
	CCMenuItemLabel* pMenuItem3 = CCMenuItemLabel::itemWithLabel(pLabel3, this, menu_selector(ControlMusic::menuCallback));
	pMenuItem3->setPosition(CCPointMake( size.width / 2,size.height/2-90));
	pMenu->addChild(pMenuItem3,1);

}

void ControlMusic::menuCallback(CCObject* pSender)
{
	//string str=pTextField->getString();
	
	CCScene *pScene = HelloWorld::scene();
	CCScene *s=  CCTransitionFadeTR::transitionWithDuration(0.5, pScene);
	CCDirector::sharedDirector()->replaceScene(s);
}

void ControlMusic::TurnOff(CCObject* pSender)
{
	if (HelloWorld::OpenMusic)
	{
		SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
		HelloWorld::OpenMusic=FALSE;
	}
	menuCallback(pSender);
}
void ControlMusic::TurnOn(CCObject* pSender)
{
	if (!HelloWorld::OpenMusic)
	{
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC[0].c_str(), true);
		HelloWorld::OpenMusic=TRUE;
	}

	menuCallback(pSender);
	
		
}